import { defineStore } from 'pinia'
import { ref, computed } from 'vue'

// 产品数据接口
export interface Product {
  id: string
  name: string
  description: string
  icon: string
  category: string
  features: string[]
  pricing: {
    daily: number
    weekly: number
    monthly: number
    quarterly: number
  }
  popular: boolean
  image?: string
}

// 订单数据接口
export interface Order {
  id: string
  productId: string
  productName: string
  type: 'daily' | 'weekly' | 'monthly' | 'quarterly'
  price: number
  status: 'pending' | 'paid' | 'active' | 'expired'
  createdAt: string
  expiresAt: string
  activationCode?: string
}

// 用户数据接口（移除了登录状态）
export interface User {
  id: string
  username: string
  email?: string
  phone?: string
  avatar?: string
}

// 主应用状态
export const useAppStore = defineStore('app', () => {
  // 移除了用户状态管理（系统无需登录）

  // 产品列表
  const products = ref<Product[]>([
    {
      id: '1',
      name: 'Cursor',
      description: '最强AI编程助手，支持Claude Code 4.5模型，智能代码补全和生成',
      icon: '🎯',
      category: 'AI编程',
      features: ['Claude Code 4.5模型', '智能代码补全', 'AI对话编程', '多语言支持', '实时协作'],
      pricing: {
        daily: 5.9,
        weekly: 16.9,
        monthly: 39.9,
        quarterly: 99.9
      },
      popular: true,
      image: '/cursor-logo.png'
    }
  ])

  // 订单列表
  const orders = ref<Order[]>([])

  // 计算属性
  const popularProducts = computed(() => 
    products.value.filter(product => product.popular)
  )

  const userOrders = computed(() => 
    orders.value.filter(order => order.status === 'active')
  )

  // 移除了登录和登出方法

  // 添加订单
  const addOrder = (order: Omit<Order, 'id' | 'createdAt'>) => {
    const newOrder: Order = {
      ...order,
      id: Date.now().toString(),
      createdAt: new Date().toISOString()
    }
    orders.value.push(newOrder)
    return newOrder
  }

  // 获取产品详情
  const getProductById = (id: string) => {
    return products.value.find(product => product.id === id)
  }

  return {
    // 状态
    products,
    orders,
    
    // 计算属性
    popularProducts,
    userOrders,
    
    // 方法
    addOrder,
    getProductById
  }
})
